package top.ucat.x.system.controller.management;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ucat.box.cloud.common.result.Result;
import top.ucat.box.cloud.common.result.SystemResult;
import top.ucat.box.starter.mybatis.plus.base.controller.AbstractBaseController;
import top.ucat.x.system.entity.SysDeptRole;
import top.ucat.x.system.entity.SysRole;
import top.ucat.x.system.entity.SysRolePermission;
import top.ucat.x.system.service.management.SysRolePermissionService;
import top.ucat.x.system.service.management.SysRoleService;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Jun
 * @since 2019-06-12
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController extends AbstractBaseController<SysRole, SysRoleService> {

    @Autowired
    private SysRolePermissionService sysRolePermissionService;

    /**
     * 设置角色权限
     *
     * @param permissions
     * @return
     */
    @PostMapping("permission")
    public Result saveRolePermission(@RequestBody List<SysRolePermission> permissions) {
        sysRolePermissionService.saveRolePermissions(permissions);
        return SystemResult.OK.getResult();
    }

    /**
     * 获取角色类型的权限
     *
     * @param roleId
     * @param type
     * @return
     */
    @GetMapping("permission")
    public Result getRolePermission(String roleId, Integer type) {
        List<SysRolePermission> rolePermissions = sysRolePermissionService.getRolePermissions(roleId, type);
        return SystemResult.OK.getResult(rolePermissions);
    }

}

